IF EXISTS (SELECT * FROM sysobjects WHERE name = 'BreakListToIntByDelimeter' AND type IN ('FN','IF','TF'))
     DROP FUNCTION dbo.BreakListToIntByDelimeter
GO

CREATE FUNCTION dbo.BreakListToIntByDelimeter
     ( @ListToBreak varchar(8000),
       @Delimeter   char(1) )
RETURNS @ReturnValue TABLE ( BrokenList int )
AS
/*
 *
 * BreakListToIntByDelimeter
 *
 * Purpose:      
 *
 * Inputs:       
 *
 * Assumes:      
 *
 * Effects:      
 *
 * Returns:      
 *
 * Calling
 * Application:  
 *
 * Note(s):      
 *
 * Author(s):    NOVA Concepts Ltd.
 *
 * Change Log:   Initial Release, 06/15/2009, 1.00.0000
 *
 */
BEGIN
     DECLARE @Len    int,
             @StPos  int,
             @EndPos int,
             @WK     varchar(8000)

     -- Add a delimiter to list so we know we have a place to stop
     SELECT @ListToBreak = @ListToBreak + @Delimeter,
            @Len         = LEN(@ListToBreak) + 1,
            @StPos       = 1

     WHILE ( @StPos < @Len )
     BEGIN
          SELECT @EndPos = CHARINDEX( @Delimeter, @ListToBreak, @StPos )
          SELECT @WK = SUBSTRING( @ListToBreak, @StPos, @EndPos - @StPos )

          IF NOT ( @WK IS NULL or @WK = '' )
          BEGIN 
               INSERT @ReturnValue( BrokenList ) SELECT CONVERT( int, @WK )
          END

          SET @StPOS = @EndPos + 1
     END

     RETURN 
END
GO
